package studiodiva.portfolio.client.lib.view;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.Widget;

class CkEditor {
  private static boolean initialized;

  public static void initialize() {
    if (initialized) return;
    JsInject.injectSrc("ckeditor/ckeditor.js");
    initialized = true;
  }

  private final JavaScriptObject instance;

  public CkEditor(Widget widget) {
    instance = replaceImpl(widget.getElement());
  }

  public void close() {
    closeImpl(instance);
  }

  private native void closeImpl(JavaScriptObject ckeditor) /*-{
		ckeditor.destroy();
  }-*/;

  private native JavaScriptObject replaceImpl(Element element) /*-{
		return $wnd.CKEDITOR.replace(element);
  }-*/;
}